package com.nit.netty.listener;

import com.google.common.collect.Lists;
import com.nit.netty.manager.NettyChannelManager;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;
import org.apache.zookeeper.KeeperException;

import java.util.concurrent.TimeUnit;

/**
 * @Author: whb
 * @Description:
 * @CreateTime: 2020/8/21 13:47
 */
public class ConnectionListener implements ChannelFutureListener {
    private final static Integer DEFAULT_RETRY_COUNT = 5;
    private NettyChannelManager manager;

    public ConnectionListener(NettyChannelManager manager) {
        this.manager = manager;
    }

    // 一个channelFuture的监听器, future完成后无论成功与否都会调用这个方法
    // 可以在这里做一些事情, 比如重连操作
    @Override
    public void operationComplete(ChannelFuture channelFuture) throws Exception {
        if (!channelFuture.isSuccess()) {
            System.err.println("服务端断开连接...");
        } else {
            System.out.println("服务端链接成功...");
        }
    }
}
